package org.example;

import com.linkedin.common.urn.DatasetUrn;
import com.linkedin.common.urn.Urn;
import com.linkedin.common.urn.UrnUtils;
import com.linkedin.dataset.DatasetLineageType;
import com.linkedin.metadata.aspect.patch.builder.UpstreamLineagePatchBuilder;
import datahub.client.MetadataWriteResponse;
import datahub.client.rest.RestEmitter;

import org.example.model.ColumnLineage;
import org.example.model.TableLineage;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import static org.example.DataHubUtil.getDateSet;

import static org.example.FlinkDDLParser.parseSql;

public class Main {
    public static void main(String[] args) throws URISyntaxException, IOException, ExecutionException, InterruptedException {
        System.out.println("开始运行");
        SeatunnelParserv2.main(args);


        Timer timer = new Timer();
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 1); // 每天 1 点
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);

        Date firstTime = calendar.getTime();
        if (firstTime.before(new Date())) {
            // 如果时间已过，则从明天开始
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            firstTime = calendar.getTime();
        }

        // 每天执行一次，周期为 24 小时
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                System.out.println("任务执行时间: " + new Date());
                SeatunnelParserv2.main(args);
                // 执行任务逻辑
            }
        }, firstTime, 24 * 60 * 60 * 1000);
    }
}
